package com.dhcc.core.modules.system.controller;

import java.util.List;

import com.dhcc.core.framework.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.modules.system.entity.UserOnline;
import com.dhcc.core.modules.system.service.ISessionService;


@Controller
@RequestMapping("${sys.backendPath}/session")
public class SessionController extends BaseController {
	
	@Autowired
	ISessionService sessionService;
	
    private String PREFIX = "/backend/system/session/";
	
	@RequestMapping
	public String online() {
        return PREFIX + "session.html";
	}

	@ResponseBody
	@RequestMapping("sessionId")
	public String getSessionId() { return super.getSession().getId(); }

	@ResponseBody
	@RequestMapping("list")
    public Object list(@RequestParam(required=false) String searchKey) {
		List<UserOnline> list = sessionService.list(searchKey);
		return list;
	}

	@ResponseBody
	@Permission("session:kickout")
	@RequestMapping("kickout")
	public R forceLogout(String id) {
		try {
			sessionService.forceLogout(id);
			return R.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return R.error("踢出用户失败");
		}

	}
}
